<template>
  <div style="width: 100%">

    <el-row>
      <el-col :span="20"><h1>进销存管理系统</h1></el-col>
      <el-col :span="4"><div style="text-align: center;line-height: 84.48px" v-if="loginUser == ''">你好,请先<router-link to="/login">登陆</router-link></div>
        <div v-else>欢迎光临,{{loginUser.userName}}</div></el-col>
    </el-row>

    <el-row>
      <el-col :span="4" style="height: 500px;background-color: #545c64">
        <el-menu
            active-text-color="#ffd04b"
            background-color="#545c64"
            class="el-menu-vertical-demo"
            default-active="2"
            text-color="#fff"
            @open="handleOpen"
            @close="handleClose"
        >
          <el-sub-menu index="1"  v-if="1 in power || 2 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>资料管理</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item v-if="1 in power" index="1-1" @click="$router.push('/Index/supplier')">
                供应商管理
              </el-menu-item>
              <el-menu-item v-if="2 in power" index="1-2" @click="$router.push('/Index/customer')">
                客户管理
              </el-menu-item>
            </el-menu-item-group>
          </el-sub-menu>

          <el-sub-menu index="2"  v-if="3 in power || 4 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>采购管理</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item v-if="3 in power" index="2-1" @click="$router.push('/Index/buyer')">
                采购入库
              </el-menu-item>
              <el-menu-item v-if="4 in power" index="2-2" @click="$router.push('/Index/buyerInfo')">
                采购信息管查询
              </el-menu-item>

            </el-menu-item-group>
          </el-sub-menu>

          <el-sub-menu index="3"  v-if="5 in power || 6 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>销售管理</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item v-if="5 in power" index="3-1" @click="$router.push('/Index/sell')">
               销售出库
              </el-menu-item>
              <el-menu-item v-if="6 in power" index="3-2" @click="$router.push('/Index/sellInfo')">
                销售信息查询
              </el-menu-item>
            </el-menu-item-group>

          </el-sub-menu>

          <el-sub-menu index="4"  v-if="7 in power || 8 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>库存管理</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item v-if="7 in power" index="4-1" @click="$router.push('/Index/product')">
                库存一览
              </el-menu-item>

            </el-menu-item-group>
          </el-sub-menu>


          <el-sub-menu index="5"  v-if="8 in power || 9 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>统计信息</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item v-if="11 in power" index="5-1" @click="$router.push('/Index/countSell')">
                销售统计
              </el-menu-item>
              <el-menu-item v-if="11 in power" index="5-2" @click="$router.push('/Index/countMonthSell')">
                月销售统计
              </el-menu-item>
            </el-menu-item-group>


          </el-sub-menu>

          <el-sub-menu index="6"  v-if="10 in power || 11 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>权限管理</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item v-if="10 in power" index="6-1" @click="$router.push('/Index/user')">
                用户管理
              </el-menu-item>
              <el-menu-item v-if="11 in power" index="6-2" @click="$router.push('/Index/role')">
               角色管理
              </el-menu-item>

            </el-menu-item-group>


          </el-sub-menu>

          <el-sub-menu index="7"  v-if="1 in power || 2 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>个人信息管理</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item index="7-1" @click="$router.push('/Index/changePwd')">
                修改密码
              </el-menu-item>

            </el-menu-item-group>


          </el-sub-menu>

          <el-sub-menu index="8"  v-if="1 in power || 2 in power">
            <template #title>
              <el-icon><location /></el-icon>
              <span>日志信息</span>
            </template>
            <el-menu-item-group title="Group One">
              <el-menu-item index="8-1" @click="$router.push('/Index/journal')">
                日志一览
              </el-menu-item>

            </el-menu-item-group>
          </el-sub-menu>
        </el-menu>
      </el-col>
      <el-col :span="20" ><router-view/></el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios";
export default {
name: "index",
data(){
    return{
      loginUser:{},
      power:[]
        }
    },
  methods:{

  },
  created() {

  },
  beforeCreate() {
    axios.get("/project/user/getLoginUser").then(resp => {
      this.loginUser = resp.data;
      axios.get("/project/user/findById", {
        params: {
          id: resp.data.id,
        }
      }).then(resp => {
        resp.data.powerSet.forEach(e => {
          this.power.push(e.id + '');
        });
      })
    })
  }
}
</script>

<style scoped>

</style>